//
//  SectionHeaderView.m
//  EPTool
//
//  Created by guoshiqing on 2018/4/12.
//  Copyright © 2018年 云数动能科技. All rights reserved.
//

#import "SectionHeaderView.h"
#import <Masonry.h>
#import "Macro.h"

@implementation SectionHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        
    }
    return self;
}

- (void)setTitle:(NSString *)title
{
    [self setTitle:title andDetailTitle:nil];
}

- (void)setTitle:(NSString *)title andDetailTitle:(NSString *)detailTitle
{
    self.titleLabel.text = title;
    if (detailTitle && detailTitle.length > 0) {
        [self.detailLabel setHidden:NO];
        [self.detailLabel setText:detailTitle];
    }
    else{
        [_detailLabel setHidden:YES];
    }
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = RGB_HEX(0x53565b);
        _titleLabel.font = [UIFont systemFontOfSize:14];
        [self.viwBottom addSubview:_titleLabel];
        
        WEAKSELF
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.viwBottom.mas_left).mas_offset(16);
            make.centerY.mas_equalTo(weakSelf.viwBottom.mas_centerY).mas_offset(2);
        }];
        
    }
    return _titleLabel;
}

- (UIView *)viwBottom
{
    if (!_viwBottom) {
        _viwBottom = [[UIView alloc] init];
        _viwBottom.backgroundColor = RGB_HEX(0xf0f0f0);
        [self.contentView addSubview:_viwBottom];
        WEAKSELF
        [_viwBottom mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(weakSelf.contentView.mas_top);
            make.left.equalTo(weakSelf.contentView.mas_left);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom);
            make.right.equalTo(weakSelf.contentView.mas_right);
            make.width.equalTo(weakSelf.contentView.mas_width);
        }];
        
    }
    return _viwBottom;
}
- (UILabel *)detailLabel
{
    if (!_detailLabel) {
        _detailLabel = [[UILabel alloc] init];
        [self.viwBottom addSubview:_detailLabel];
        _detailLabel.textColor = RGB_HEX(0xf0f0f0);
        _detailLabel.font = [UIFont systemFontOfSize:14];
        
        WEAKSELF
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.titleLabel.mas_right).mas_offset(5);
            make.centerY.mas_equalTo(weakSelf.titleLabel.mas_centerY);
        }];
    }
    return _detailLabel;
}

- (UIView *)viwLine
{
    if (!_viwLine) {
        _viwLine = [[UIView alloc] init];
        _viwLine.backgroundColor = RGB_HEX(0xdedede);
        [self.viwBottom addSubview:_viwLine];
        WEAKSELF
        [_viwLine mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(weakSelf.viwBottom.mas_bottom);
            make.right.equalTo(weakSelf.viwBottom.mas_right);
            
            make.height.mas_equalTo(UI_1_PX_SIZE);
            make.left.equalTo(weakSelf.titleLabel.mas_left);
            
        }];
    }
    return _viwLine;
}
+ (CGFloat)getSectionHeaderHeight
{
    return 36;
}

@end
